# http://www.rubyonrailsblog.com/articles/2007/04/16/scope-and-ruby-on-rails-scope_out-and-more

class Person < ActiveRecord::Base
  scope_out :women, :conditions => ['people.sex = ?', 'F']
end

# which creates



class Person < ActiveRecord::Base
  def Person.with_women
    with_scope :find => {:conditions => ['people.sex => ?', 'F']} do
      yield
    end
  end

  def Person.find_women(*args)
    with_women {find(*args)}
  end

  def Person.calculate_women(*args)
    with_women {calculate(*args)}
  end
end

#################################

class Person < Sequel::Model(:people)
  subset :women, ['people.sex = ?', 'F']
end

# in Sequel, subset gives us a dataset that can be used as follows:

Person.women.filter(:age => 21..30).count #=> count all women aged 21 to 30

Person.women.filter(:first_name => 'Jenny').all #=> get all women named Jenny

Person.women.count #=> count all women

# And no magic. That's cool.